<?php

/**
 * This is the model class for table "tbl_adv".
 *
 * The followings are the available columns in table 'tbl_adv':
 * @property integer $id
 * @property string $type_adv
 * @property integer $category_id
 * @property integer $type
 * @property integer $marka
 * @property integer $model
 * @property integer $year
 * @property integer $probeg
 * @property string $color
 * @property integer $obiem
 * @property string $price
 * @property string $info
 * @property string $phone
 * @property string $address
 * @property string $date_off
 * @property integer $is_active
 *
 * The followings are the available model relations:
 * @property TblAdvCategory $category
 * @property TblAdvTypeCategory $type0
 * @property TblAdvModel $model0
 */
class Adv extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Adv the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_adv';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('category_id, type, price, phone, date_off', 'required'),
			array('category_id, type, marka, model, year, probeg, obiem, is_active', 'numerical', 'integerOnly'=>true),
			array('type_adv', 'length', 'max'=>1),
			array('color', 'length', 'max'=>50),
			array('price', 'length', 'max'=>10),
			array('phone, address', 'length', 'max'=>255),
			array('info', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, type_adv, category_id, type, marka, model, year, probeg, color, obiem, price, info, phone, address, date_off, is_active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'category' => array(self::BELONGS_TO, 'AdvCategory', 'category_id'),
			'types' => array(self::BELONGS_TO, 'AdvTypeCategory', 'type'),
			'models' => array(self::BELONGS_TO, 'AdvModel', 'model'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type_adv' => 'Type Adv',
			'category_id' => 'Category',
			'type' => 'Type',
			'marka' => 'Marka',
			'model' => 'Model',
			'year' => 'Year',
			'probeg' => 'Probeg',
			'color' => 'Color',
			'obiem' => 'Obiem',
			'price' => 'Price',
			'info' => 'Info',
			'phone' => 'Phone',
			'address' => 'Address',
			'date_off' => 'Date Off',
			'is_active' => 'Is Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('type_adv',$this->type_adv,true);
		$criteria->compare('category_id',$this->category_id);
		$criteria->compare('type',$this->type);
		$criteria->compare('marka',$this->marka);
		$criteria->compare('model',$this->model);
		$criteria->compare('year',$this->year);
		$criteria->compare('probeg',$this->probeg);
		$criteria->compare('color',$this->color,true);
		$criteria->compare('obiem',$this->obiem);
		$criteria->compare('price',$this->price,true);
		$criteria->compare('info',$this->info,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('date_off',$this->date_off,true);
		$criteria->compare('is_active',$this->is_active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}